package dao;

// Generated 04-Apr-2011 11:04:34 by Hibernate Tools 3.4.0.CR1

import java.util.List;

import hibernate.HibernateDAO;
import beans.TbMaquina;
import javax.ejb.Stateless;
import org.hibernate.criterion.Order;

@Stateless
public class TbMaquinaDAO extends HibernateDAO<TbMaquina, Integer> {
	public List<TbMaquina> listarMaquinas(){
		return listAll(Order.asc("maquinaCod"));
	}
	
	@SuppressWarnings("unchecked")
	public List<String> ListarMaqDescr(){
		return this.session.createQuery("Select concat(maquinaCod, ' - ', maquinaDescr)  from TbMaquina order by maquinaCod asc").list();
	}
	
	public List<TbMaquina> ListarMaquina(String codProduto) {
		return listByQuery("from TbMaquina m where m.maquinaCod in (select p.id.prodmaqCodmaquina from TbProdmaq p where p.id.prodmaqCodprod = " + codProduto + ")");
	}
	
	public List<String> ListarMaquinaCodProd(String codProduto) {
		return this.session.createQuery("Select m.maquinaCod || ' - ' || m.maquinaDescr from TbMaquina m where m.maquinaCod in (select p.id.prodmaqCodmaquina from TbProdmaq p where p.id.prodmaqCodprod = " + codProduto + ")").list();
	}
}
